/*
 * Ext JS Library 2.2
 * Copyright(c) 2006-2008, Ext JS, LLC.
 * licensing@extjs.com
 * 
 * http://extjs.com/license
 */

Ext.onReady(function() {
    Ext.QuickTips.init();

    // turn on validation errors beside the field globally
    Ext.form.Field.prototype.msgTarget = 'side';
    var return_url = Ext.urlDecode(window.location.search.substring(1))['returnUrl'];
    if (!return_url) {
        return_url = 'index';
    }
    var loginForm = new Ext.FormPanel({
        id: 'pnlLogin',
        renderTo: 'login-form',
        frame: true,
        title: lbl_title,
        bodyStyle: 'padding:5px 5px 0 0',
        labelAlign: 'right',
        height: 220,
        width: 300,
        waitMsgTarget: true,
        layout: 'form',
        items: [{
            xtype: 'fieldset',
            id: 'fsLogin',
            title: lbl_form_title,
            height: 120,
            width: 280,
            labelWidth: 80,
            items: [{
                xtype: 'textfield',
                id: 'email',
                fieldLabel: lbl_email,
                name: 'email',
                width: 150,
                allowBlank: false
            },
            {
                xtype: 'textfield',
                fieldLabel: lbl_password,
                name: 'password',
                inputType: 'password',
                width: 150,
                allowBlank: false
            },
            {
                buttons: [{
                    text: btn_login,
                    type: 'submit',
                    name: 'login',
                    handler: function() {
                        var form = loginForm.getForm();
                        if (form.isValid()) {
                            form.submit({
                                url: login_url,
                                waitMsg: msg_login,
                                success: function(form, action) {
                                    //alert(action.result.msg);                                        
                                    window.location = return_url;
                                }
                            });
                        }
                    }
                }]
            }]
        },
        {
            xtype: 'panel',
            id: 'pnlLabel',
            border: false,
            height: 80,
            items: [{
                xtype: 'label',
                id: 'lblRegisterUser',
                autoWidth: true,
                name: 'registerUser',
                html: reg_link
            },
            {
                xtype: 'label',
                id: 'lblResetPassword',
                autoWidth: true,
                name: 'resetPassword',
                html: forgot_pass
            }]
        }]
    });
    Ext.getCmp('email').focus();
});